// pages/coupons/coupons.js
Page({
  data: {
    data: [],
    isBlock: false,
    isNone: true,
    couponInfo: null,
    count: '0',
    history: [{ name: '可用点券' }, { name: '历史消费' }, { name: '兑换点券' }]
  },
  select: function (event) {
    console.log(event.target)
    var that = this;
    that.setData({
      count: event.target.dataset.index
    })
    var offsetLeft = event.target.offsetLeft;
    if (offsetLeft == 3) {
      this.setData({
        isBlock: false,
        isNone: true
      })
    } else if (offsetLeft == 189) {
      this.setData({
        isBlock: true,
        isNone: false
      })
    }
  },

  onLoad: function (options) {
    var userInfo = wx.getStorageSync("userInfo");
    var that = this;
    console.log(userInfo);
    wx.request({
      url: 'http://1.aiym.applinzi.com/aiyouwai.php',
      data: {
        type: 'getCoupons',
        paras: {
          uid: userInfo.uid
        },
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: { "Content-Type": "application/json" }, // 设置请求的 header
      success: function (res) {
        // success
        console.log(res.data)
        that.setData({
          couponInfo: res.data
        })
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  nick: function (event) {
    console.log(event.currentTarget.dataset);
    var cid = event.currentTarget.dataset.cid;
    var unit = event.currentTarget.dataset.unit;
    // wx.setStorageSync({
    //   key: 'unit',
    //   data: unit,
    // }) 
    wx.setStorage({
      key: 'key',
      data: {
        unit: unit,
        cid: cid
      },
    })
    wx.navigateBack({
      delta: 1
    });
  },
})